package com.example.myapplication.ContentTest;

import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.MenuItem;
import android.widget.ListView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.example.myapplication.R;
import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList;
import java.util.List;

public class ContactInfoActivity extends AppCompatActivity {
  private ViewPager viewPager;
  private TabLayout tabLayout;
  private ListView listView;
  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content_provider_contact_info_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("联系人");
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    Init();


  }

  @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        GoBack();
        break;
    }
    return true;
  }

  private void GoBack() {
    finish();
  }

  private void Init() {
    //初始化ViewPager和TabLayout
    viewPager =(ViewPager) findViewById(R.id.viewPager);
    tabLayout = (TabLayout) findViewById(R.id.tabLayout);

    //创建Fragment列表
    ArrayList<Fragment> fragmentList = new ArrayList<>();
    fragmentList.add(new ContactsInfoFragment());
    fragmentList.add(new ContactsModifyFragment());
    //创建FragmentPagerAdapter（已过时）并设置ViewPager的适配器

    //创建FragmentStatePagerAdapter(自定义)，并设置ViewPager的适配器
    FragmentStatePagerAdapter pagerAdapter =
        new FragmentStatePagerAdapter(this,getSupportFragmentManager(), fragmentList);
    viewPager.setAdapter(pagerAdapter);
    //将ViewPager与TabLayout关联
    tabLayout.setupWithViewPager(viewPager);



  }
}
